package com.just.springbootnosql.controller;

import com.just.springbootnosql.dao.UserDao;
import com.just.springbootnosql.domain.User;
import com.just.springbootnosql.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserDao userDao;
    @Autowired
    UserService userService;
    @RequestMapping("/save")
    public User saveUser(){
        User user=new User("1","哈哈哈",11);
        userDao.save(user);
        userDao.stringRedisTemplateDemo();
        return user;
    }
    @GetMapping("/getString")
    public String getString(){
       return userDao.getString();
    }

    @GetMapping("/getUser")
    public User getUser(){
        return userDao.getUser("1");
    }
    @GetMapping("/findRedis")
    public String findRedis(){
        return userService.findRedis();
    }
    @GetMapping("/testList")
    public List<User> findList(){
        return userService.cacheUsers();
    }
    @GetMapping("/map")
    public Map<String,User> findMap(){
        return userService.cacheUserMap();
    }
    @GetMapping("/getFromMap")
    public User findOneFromMap(String id){
        return userService.findUser(id);
    }
    @GetMapping("/set")
    public Set<User> findFromSet(){
        return userService.cacheUserSet();
    }
    @GetMapping("/zset")
    public Set<User> findFromZSet(){
        return userService.cacheUserZSet();
    }
}
